home *** CD-ROM | disk | FTP | other *** search
Wrap
VERSION 2.00 Begin Form frmINI Caption = "Read/Write to INI" ClientHeight = 3465 ClientLeft = 1710 ClientTop = 1545 ClientWidth = 4875 Height = 3870 Left = 1650 LinkMode = 1 'Source LinkTopic = "Form1" ScaleHeight = 3465 ScaleWidth = 4875 Top = 1200 Width = 4995 Begin TextBox txtsample Height = 285 Left = 600 MaxLength = 15 TabIndex = 9 Top = 360 Width = 2415 End Begin CommandButton cmdExit Caption = "Exit" Height = 495 Left = 3480 TabIndex = 8 Top = 2760 Width = 1215 End Begin CommandButton cmdRead Caption = "Read" Height = 495 Left = 3480 TabIndex = 7 Top = 1800 Width = 1215 End Begin CommandButton cmdWrite BackColor = &H00000000& Caption = "Write" Height = 495 Left = 3480 TabIndex = 6 Top = 960 Width = 1215 End Begin CheckBox chkBlue Caption = "Blue" Height = 495 Left = 2160 TabIndex = 5 Top = 2640 Width = 1215 End Begin CheckBox chkGreen Caption = "Green" Height = 495 Left = 2160 TabIndex = 4 Top = 1800 Width = 1215 End Begin CheckBox chkRed Caption = "Red" Height = 495 Left = 2160 TabIndex = 3 Top = 960 Width = 1215 End Begin Label lblSampletxt Caption = "Sample text" Height = 255 Left = 600 TabIndex = 10 Top = 120 Width = 1815 End Begin Label lblBlue BackColor = &H00FF0000& Height = 495 Left = 600 TabIndex = 2 Top = 2640 Visible = 0 'False Width = 1215 End Begin Label lblGreen BackColor = &H0000FF00& Height = 495 Left = 600 TabIndex = 1 Top = 1800 Visible = 0 'False Width = 1215 End Begin Label lblRed BackColor = &H000000FF& Height = 495 Left = 600 TabIndex = 0 Top = 960 Visible = 0 'False Width = 1215 End Option Explicit Declare Function GetPrivateProfileInt Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Integer, ByVal lpFileName As String) As Integer Declare Function GetPrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer Declare Function WritePrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, lpKeyName As Any, lpString As Any, ByVal lplFileName As String) As Integer 'Declare Function WritePrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As string, byVal lpString As string, ByVal lplFileName As String) As Integer 'The second WritePrivateProfileString seems to work better than the Declared copied from the Help file. ' rc = WritePrivateProfileString(Sectionname, keyname, keyvalue, filename) Sub chkBlue_Click () If ChkBlue.Value = 1 Then lblBlue.Visible = True lblBlue.Visible = False End If End Sub Sub chkGreen_Click () If ChkGreen.Value = 1 Then lblGreen.Visible = True lblGreen.Visible = False End If End Sub Sub chkRed_Click () If ChkRed.Value = 1 Then lblRed.Visible = True lblRed.Visible = False End If End Sub Sub cmdExit_Click () End End Sub Sub cmdRead_Click () Dim rc As Integer Dim keyvalue As String Dim keydefault As String Dim keyname As String Dim Sectionname As String Dim filename As String filename = "Marc.INI" Sectionname = "INI Sample" keyname = "Sample Text" keydefault = "INI Sample" keyvalue = String$(16, 0) rc = GetPrivateProfileString(Sectionname, keyname, keydefault, keyvalue, Len(keyvalue), filename) txtSample = keyvalue ChkRed.Value = GetPrivateProfileInt(Sectionname, "Red", 0, filename) ChkGreen.Value = GetPrivateProfileInt(Sectionname, "Green", 0, filename) ChkBlue.Value = GetPrivateProfileInt(Sectionname, "Blue", 0, filename) End Sub Sub cmdWrite_Click () Dim rc As Integer Dim keyname As String Dim keyvalue As String Dim Sectionname As String Dim filename As String Sectionname = "INI Sample" filename = "Marc.ini" keyname = "Sample Text" keyvalue = txtSample keyname = "Sample Text" keyvalue = txtSample.Text rc = WritePrivateProfileString(Sectionname, ByVal keyname, ByVal keyvalue, filename) keyname = "Red" keyvalue = Str$(ChkRed.Value) rc = WritePrivateProfileString(Sectionname, ByVal keyname, ByVal keyvalue, filename) keyname = "Green" keyvalue = Str$(ChkGreen.Value) rc = WritePrivateProfileString(Sectionname, ByVal keyname, ByVal keyvalue, filename) keyname = "Blue" keyvalue = Str$(ChkBlue.Value) rc = WritePrivateProfileString(Sectionname, ByVal keyname, ByVal keyvalue, filename) End Sub